import myAxios from '@/utils/config/axiosConfig'
import type { Article } from '@/utils/dataType/ArticleModel'

/**
 * 该文件用于和游记相关的api接口
 */

/**
 * 用户保存文章为草稿
 * @param params
 * @returns
 */
export const putDraftArticle = async (params: Article) => {
  const res = await myAxios.request({
    url: '/user/article/publishArticle',
    method: 'POST',
    data: params,
  })
  return res
}
/**
 * 用户请求发布文章->随后文章进入待审核状态
 * @param params
 * @returns
 */
export const putPublishArticle = async (params: Article) => {
  const res = await myAxios.request({
    url: '/user/article/publishArticle',
    method: 'POST',
    data: params,
  })
  return res
}
/**
 * 用户上传文章封面，和图片
 * @param params
 * @returns 返回的data中有路径信息
 */
export const uploadImage = async (FormData: FormData) => {
  const res = await myAxios.request({
    url: '/user/article/uploadImage',
    method: 'PUT',
    data:FormData, //传递data数据
    headers: {
      // 'Content-Type': 'multipart/form-data',
    },
  })
  return res
}
/**
 * 用户获取相关推荐的游记文章
 * @returns
 */
export const getRecommendRelevantPassage = async () => {
  const res = await myAxios.request({
    url: '/user/forum/recommend-article-relevant',
    method: 'GET',
  })
  return res
}
/**
 * 用户获取最新的游记文章推荐
 * @returns
 */
export const getRecommendLatestPassage = async () => {
  const res = await myAxios.request({
    url: '/user/forum/latest',
    method: 'GET',
  })
  return res
}
/**
 * 用户获取周/月/年热度较高的文章推荐（根据浏览量推荐）
 * @returns
 */
export const getRecommendTopPassage = async (params: { range: string }) => {
  const res = await myAxios.request({
    url: '/user/forum/recommend-article-top',
    method: 'GET',
    params, //作为query参数发送到后端
  })
  return res
}
/**
 * 用户获取游记的详情信息内容
 * @param params
 */
export const fetchArticleDetail = async (params: { articleId: number }) => {
  const res = await myAxios.request({
    url: '/user/article/show',
    method: 'GET',
    params,
  })
  return res
}
/**
 * 用户获取游记的顶级评论
 * @returns
 */
export const fetchArticleComments = async (params: {
  articleId: number
  page: number //当前看哪一页
  pageSize: number //每一页展示多少数据
}) => {
  const res = await myAxios.request({
    url: '/user/article/showTopComments',
    method: 'GET',
    params,
  })
  return res
}
/**
 * 用户提交顶层评论（对文章）
 * @param params
 * @returns
 */
export const putArticleComment = async (params: { articleId: number; comment: string }) => {
  const res = await myAxios.request({
    url: '/user/article/toComment',
    method: 'POST',
    params,
  })
  return res
}
/**
 * 用户获取顶级评论的回复
 */
export const fetchCommentsReply = async (params: { topId: number }) => {
  const res = await myAxios.request({
    url: '/user/article/showSubComments',
    method: 'GET',
    params, //给评论的id
  })
  return res
}
/**
 * 用户给评论做回复
 * @returns
 */
export const putCommentReply = async (params: {
  articleId: number //文章id
  content: string //文章内容
  parentId: number //顶层评论的id
}) => {
  const res = myAxios.request({
    url: '/user/article/toCommentTop',
    method: 'POST',
    params,
  })
  return res
}
/**
 * 用户给文章点赞
 * @param params
 */
export const putLikePassage = async (params: { articleId: number }) => {
  const res = await myAxios.request({
    url: '/user/article/toLike',
    method: 'PUT',
    params,
  })
  return res
}

/**
 * 用户收藏文章
 * @param params
 */
export const putCollectPassage = async (params: { articleId: number }) => {
  const res = await myAxios.request({
    url: '/user/article/toCollect',
    method: 'PUT',
    params,
  })
  return res
}
